package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.RepairManagement;
import com.ruoyi.system.service.IRepairManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 故障报修管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/management1")
public class RepairManagementController extends BaseController {
    @Autowired
    private IRepairManagementService repairManagementService;

    /**
     * 查询故障报修管理列表
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairManagement repairManagement) {
        startPage();
        List<RepairManagement> list = repairManagementService.selectRepairManagementList(repairManagement);
        return getDataTable(list);
    }

    /**
     * 导出故障报修管理列表
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:export')")
    //@Log(title= "故障报修管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairManagement repairManagement) {
        List<RepairManagement> list = repairManagementService.selectRepairManagementList(repairManagement);
        ExcelUtil<RepairManagement> util = new ExcelUtil<RepairManagement>(RepairManagement.class);
        util.exportExcel(response, list, "故障报修管理数据");
    }

    /**
     * 获取故障报修管理详细信息
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:query')")
    @GetMapping(value = "/{repairCode}")
    public AjaxResult getInfo(@PathVariable("repairCode") String repairCode) {
        return success(repairManagementService.selectRepairManagementByRepairCode(repairCode));
    }

    /**
     * 获取故障报修管理详细信息
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:query')")
    @GetMapping("xialaxuan")
    public AjaxResult xialaxuan() {
        return success(repairManagementService.xialaxuan());
    }

    /**
     * 新增故障报修管理
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:add')")
    // //@Log(title= "故障报修管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairManagement repairManagement) {
        repairManagement.setRepairCode(IdUtils.fastSimpleUUID());
        return toAjax(repairManagementService.insertRepairManagement(repairManagement));
    }

    /**
     * 修改故障报修管理
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:edit')")
    //@Log(title= "故障报修管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairManagement repairManagement) {
        return toAjax(repairManagementService.updateRepairManagement(repairManagement));
    }

    /**
     * 删除故障报修管理
     */
    ////@PreAuthorize("@ss.hasPermi('system:management1:remove')")
    //@Log(title= "故障报修管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repairCodes}")
    public AjaxResult remove(@PathVariable String[] repairCodes) {
        return toAjax(repairManagementService.deleteRepairManagementByRepairCodes(repairCodes));
    }
}
